/**
 * 
 */
package com.hibernate.orm.onetoone;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.hibernate.orm.onetoone.domain.Card_FK;
import com.hibernate.orm.onetoone.domain.Card_PK;
import com.hibernate.orm.onetoone.domain.Person;

/**
 * @author ysitu
 *
 */
public class TestOneToOne {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		SessionFactory sessionFactory = new Configuration()
        .configure()// configures settings from hibernate.cfg.xml
        .buildSessionFactory();
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		
		Card_FK c1 = new Card_FK();
		c1.setCardNumber("1234567890");
		
		Person p1 = new Person();
		p1.setPersonName("Vincent");
		c1.setPerson(p1);
//		p1.setCard(c1);
		session.save(c1);
		session.getTransaction().commit();
		
		List result = session.createQuery("from Card_FK").list();
		for(Card_FK card : (List<Card_FK>)result)
		{
			System.out.println("Card:"+card.getCardId()+" "+card.getCardNumber()+" "+card.getPerson().getPersonId()+" "+card.getPerson().getPersonName());
//			System.out.println("Person:"+person.getPersonId()+" "+person.getPersonName()+" "+person.getCard().getCardId()+" "+person.getCard().getCardNumber());
		}
//		session.getTransaction().commit();
		session.close();
		
		
	}

}
